<template>
		<view class="icons" @click.stop="likesTap">
			<uni-icons :type="like?'heart-filled':'heart'" size="20" color="#f07373"></uni-icons>
		</view>
</template>

<script>
	export default {
		props:{
			item:{
				type:Object,
				default:() => {
					return {}
				}
			}
		},
		data() {
			return {
				like:false
			};
		},
		watch:{
			item(newVal) {
				this.like = this.item.is_like
			}
		},
		created(){
			this.like = this.item.is_like
		},
		methods:{
			likesTap(){
				this.like = !this.like
				console.log('收藏成功')
				// this.$api.update_like({
				// 	user_id:'',
				// 	article_id:this.item._id
				// }).then(res => {
				// 	console.log(res)
				// })
				this.setUpadte_like(this.item._id)
			},
			setUpadte_like(article_id){
				uni.showLoading()
				this.$api.update_like({
					user_id:'5eb6efffbae6ba004d1c74b2',
					article_id:article_id
				}).then(res => {
					console.log(res)
					uni.showToast({
					    title: this.like?'收藏成功':'取消收藏',
					    icon:'none'
					});
				}).finally(()=> {
					uni.hideLoading()
				})
			}
		}
	}
</script>

<style lang="scss">
	.icons{
					position: absolute;
					width: 20px;
					height: 20px;
					top: 0;
					right: 0;
					display: flex;
					justify-content: center;
					align-items: center;
				}
</style>
